package ACWing.Dynamicprogramming;
//898. 数字三角形
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/11/12 22:23
 */
public class TriangleOfNumbers {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[][]arr=new int[n+1][n+1];
        int[][]f=new int[510][510];//状态数组
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                arr[i][j]=sc.nextInt();
            }
        }
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= i+1; j++) {
                f[i][j]= (int) -1.0E9;//初始化状态数组
            }
        }
        f[1][1]=arr[1][1];//注意点若没有赋值将会全部小于0 ，第一个大于00下面的才会不为0
        for (int i = 2; i <=n; i++) {
            for (int j = 1; j <=i; j++) {
                f[i][j]=Math.max(arr[i][j]+f[i-1][j],arr[i][j]+f[i-1][j-1]);
            }
        }
        int max=(int) -1.0E9;
        for (int i = 0; i <= n; i++) {
            max=Math.max(max,f[n][i]);
        }
        System.out.println(max);
    }
}
